package com.example.protestgps;

import java.util.concurrent.ExecutionException;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Register extends Activity{

	Button accept;
	TextView txtRegis;
	TextView txtUser;
	TextView txtMobileNo;
	EditText edtUser;
	EditText edtMobileNo;
	TextView txtnamesurname;
	EditText edtnamesurname;
	String User;
	String namesurname;
	String MobileNo;
	String Userid;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.registor);
		
		txtRegis = (TextView) findViewById(R.id.txtRegis);
		txtUser = (TextView) findViewById(R.id.txtUser);
		txtMobileNo = (TextView) findViewById(R.id.txtMobileNo);
		edtUser = (EditText) findViewById(R.id.edtUser);
		edtMobileNo = (EditText) findViewById(R.id.edtMobileNo);
		txtnamesurname = (TextView) findViewById(R.id.txtnameandsurname);
		edtnamesurname = (EditText) findViewById(R.id.edtnameandsurname);
		accept = (Button) findViewById(R.id.btnaccept);
		
		accept.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				User = edtUser.getText().toString();
				Log.d("User",""+User);
				MobileNo = edtMobileNo.getText().toString();
				Log.d("MobileNo",""+MobileNo);
				namesurname = edtnamesurname.getText().toString();
				AsyncTask<String, String, String> AsyncTask2;
				PostRegister post = new PostRegister();
				post.dataregister(User, MobileNo,namesurname);
				AsyncTask2 = post.postre
					.execute("http://192.168.1.101/myexample/postregis.php");//192.168.1.100
				Log.d("aaa", "aaa");
				HttpPostgetUserID getuserid = new HttpPostgetUserID();
				getuserid.receivedata(User, MobileNo);
				AsyncTask<String, String, JSONObject> AsyncTask3;
				AsyncTask3  = getuserid.user_id.execute("http://192.168.1.101/myexample/getUserID.php"); ////192.168.1.100
				Log.d("pass", "pass");
				JSONObject JSONOBJ1;
				try {
				 	 JSONOBJ1 = getuserid.user_id.get();
					 Userid = JSONOBJ1.getString("UserID");
				     System.out.println("Userid: "+Userid);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ExecutionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				Intent gonext = new Intent(getBaseContext(),DataSendData.class);
				gonext.putExtra("userid", Userid);
				startActivity(gonext);
				
			}
		});
		
		
	}

}
